class RealBlood extends AcGameObject {
    constructor(playground, color, player) {
        super();
        this.playground = playground;
        this.player = player;
        this.damage = player.fireball_damage;
        this.ctx = this.playground.game_map.ctx2;
        this.y = this.ctx.canvas.height / 4;
        this.x = this.y;
        this.width = this.ctx.canvas.width * 1 / 4;
        this.height = this.ctx.canvas.height / 2;
        this.color = color;
        this.eps = 0.1;
        this.spent_time = 0;
        this.sum = 0;
        let r = this.player.playground.height * 0.05;
        while(r > this.player.playground.height * 0.011) {
            r -= this.damage;
            this.sum ++;
        }
    }

    start() {
        this.ctx.fillStyle = "red";
        this.ctx.fillRect(this.x, this.y, this.width, this.height);
    }

    update() {

        this.spent_time += this.timedelta / 1000;
        this.render();
    }

    render() {
        let percent = (this.player.radius / (this.player.playground.height * 0.05)) * this.width;
        let r_now = this.player.radius, r_base = this.player.playground.height * 0.05;
        percent = ((this.sum - ((r_base - r_now) / this.damage)) / this.sum ) *this.width
        // percent = ( (Math.PI * r_now * r_now) / (Math.PI * r_base * r_base) ) * this.width;
        // console.log(percent / this.width);
        this.ctx.fillStyle = "red";
        this.ctx.fillRect(this.x, this.y, percent, this.height);

        this.ctx.fillStyle = '#000'; // 设置文字颜色;
        this.ctx.font = '15px Arial'; // 设置文字大小和字体
        this.ctx.textAlign = 'center'; // 文字居中对齐
        this.ctx.textBaseline = 'middle'; // 文字垂直居中对齐
        let x = this.x + this.width / 2, y = this.y + this.height / 2;
        let num_blood = (percent / this.width * 100) .toFixed(2);
        let text = num_blood.toString() + "%";
        this.ctx.fillText(text, x, y);

    }
}
